package com.dpj.entity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class LitCat {

	private String AcCategoryID;
	private String AcTypeID;
	private String AcTypeName;
	public String getAcCategoryID() {
		return AcCategoryID;
	}
	public void setAcCategoryID(String acCategoryID) {
		AcCategoryID = acCategoryID;
	}
	public String getAcTypeID() {
		return AcTypeID;
	}
	public void setAcTypeID(String acTypeID) {
		AcTypeID = acTypeID;
	}
	public String getAcTypeName() {
		return AcTypeName;
	}
	public void setAcTypeName(String acTypeName) {
		AcTypeName = acTypeName;
	}
	
	public static List<LitCat> getLitCatList(String json) {
		List<LitCat> list = new ArrayList<LitCat>();
		try {
			JSONArray ja = new JSONArray(json);
			if (ja != null && ja.length() > 0) {
				for (int i = 0; i < ja.length(); i++) {
					JSONObject ja_jo = ja.optJSONObject(i);
					JSONObject jo_app = ja_jo.optJSONObject("APP");
					JSONObject jo_aos = jo_app.optJSONObject("ArrayOfAcType");
					if(jo_aos != null) {
						JSONArray ja_jo_store = jo_aos.optJSONArray("AcType");
						if (ja_jo_store != null && ja_jo_store.length() > 0) {
							for (int j = 0; j < ja_jo_store.length(); j++) {
								JSONObject jo_store = ja_jo_store.optJSONObject(j);
								LitCat litCat = new LitCat();
								litCat.setAcCategoryID(jo_store.optString("AcCategoryID"));
								litCat.setAcTypeID(jo_store.optString("AcTypeID"));
								litCat.setAcTypeName(jo_store.optString("AcTypeName"));
								list.add(litCat);
							}
						} else {
							JSONObject jo_one = jo_aos.optJSONObject("AcType");
							LitCat litCat_one = new LitCat();
							litCat_one.setAcCategoryID(jo_one.optString("AcCategoryID"));
							litCat_one.setAcTypeID(jo_one.optString("AcTypeID"));
							litCat_one.setAcTypeName(jo_one.optString("AcTypeName"));
							list.add(litCat_one);
						}
					} 
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	@Override
	public String toString() {
		return AcTypeName;
	}
	
	
}
